Untyped lambda calculus
Notes taken from Type Theory and Formal proof. An introduction
Construction principles
- Abstraction: λx.M. (read as abstraction of M over x)
- Application MN (read as application of M to N).
If it is necessary, some parentheses should be added during the construction process. e.g
Abstraction of y over λ.x−y
λy.(λx.x−y)
Functions of more than one argument: Currying
The function f(x,y)=x2+y can be write as λx.(λy.(x2+y)).
Lambda terms
Expressions in the lambda calculus are called λ−term. Λ is the set of all λ−terms. To start with, we assume the existence of an infinite set V of so-called variables: V={x,y,z,..}
- Variable: if u∈V, then u∈Λ
- Application: if M and N∈Λ, then (MN)∈Λ
- Abstraction if u∈V and M∈Λ, then (λu.M)∈Λ
so, Λ=V∣(ΛΛ)∣(λV.Λ)
Subterms
All λ−term has sub terms defined as:
- Basis: Sub(x)={x}, for each x∈V
- Application: Sub((MN))=Sub(M)∪Sub(N)∪{(MN)}
- Abstraction: Sub((λx.M))=Sub(M)∪{(λx.M)}
Subterm properties
- Reflexivity: For all λ−terms M, we have M∈Sub(M)
- Transitivity: If L∈Sub(M) and M∈Sub(N), then L∈Sub(N)
Proper subterm
L is a proper subterm of M if L is a subterm of M, but L≡M
Free and bound variables
- binding variable: variable after λ e.g. λx.
- bound variable: If a binding variable is used in the expression it is bound in the expression
Free variables definition
FV is the set of free variables of a λ−term
- Variable: FV(x)={x}
- Application: FV(MN)=FV(M)∪FV(N)
- Abstraction: FV(λx.M)=FV(M)∖{x}
Closed λ−term
The λ−term M is closed if FV(M)=∅. A closed λ−term is also called a combinator. The set of all closed λ−terms is denoted by λ0
α−conversion
It is the possibility of renaming binding (and bound) variables.
Let Mx→y denote the result of replacing every free occurrence of x in M by y. defined as:
λx.M=αλy.Mx→y, provided that y∈/FV(M) and y is not a binding variable in M
Properties
- Compatibility: if M=αN, then ML=αNL, LM=αLN and, for arbitrary z, λz.M=αλz.N
- Reflexivity: M=αM
- Symmetry: If M=αN then N=αM
- Transitivity: If both L=αM and M=αN, then L=αN
α−variant
If M=αN, then M and N are said to be α−convertible or α−equivalent. M is called an α−variant of N (and vice versa)
Function evaluation process β−reduction
An expression of the form (λx.M)N can be rewritten to the expression M[x:=N], i.e. the expressions M in which every x has been replaced with N. We call this process β−reduction of (λx.M)N to M[x:=N]. e.g
- (λx.x2+1)(3) reduces to (x2+1)[x:=3] which is 32+1.
- (λz.(λx.x)(λy.y)) reduces to (λz.(λy.y))
Application is the construction of new expression, not the execution of the expression. It is only after the reduction of the latter term that we obtain the result of the application
Substitution
- x[x:=N]≡N
- y[x:=N]≡y if x≡y
- (PQ)[x:=N]≡P[x:=N] Q[x:=N]
- (λy.P)[x:=N]≡λz.(Py→z[x:=N]), if λz.Py→z is an α−variant of λy.P such that z∈/FV(N)
One step β-reduction →β
The incentive to defining the relation →β is the presence of an application term where the first part is an abstraction: λx.M. Since an abstraction can be thought of as representing a function, we can conceive of part N as an argument for this function.
- Basis: (λx.M)N→βM[x:=N]
- The subterm of the form (λx.M)N on the left hand side is called a redex (from reducible expression). The subterm M[x:=N] on the right hand side is called the contractum (of the redex)
- Compatibility: (M→βN), then ML→βNL, LM→βLN and λx.M→βλx.N
Zero or more steps β-reduction ↠β
M↠βN if there is n≥0 and there are terms M0 to Mn such that M0≡M, Mn≡N and for all i such that 0≤i<n: Mi→βMi+1
Hence, if M↠βN, there exists a chain of single-step β-reductions, starting with M and ending with N:
M≡M0→βM1→βM2→β⋯→βMn−2→βMn−1→βMn≡N
Lemma:
- ↠β extends →β, i.e. if M→βN, then M↠βN.
- ↠β is reflesive and transitive, i.e:
- (refl): for all M:M↠βM,
- (trans): for all L, M and N: if L↠βM and M↠βN then L↠βN.
β-conversion, β-equality, =β
M=βN if there is an n≥0 and there are terms M0 to Mn such that M0≡M,Mn≡N and for all i such that 0≤i<n: either Mi→βMi+1 or Mi+1→βMi
For example: (λy.yv)z=β(λx.zx)v since we have the following chain, where ←β is the inverse of →β:
(λy.yv)z→βzv←β(λx.zx)v
=β is an equivalence relation, hence reflexive, symmetric and transitive
- M is in β-normal form if M does not contain any redex
- M has a β-normal form if there is an N in β-normal form that M=βN. Such an N is a β-normal form of M
When M is in β-nf, then M↠βN implies M≡N
Fixed point theorem
For all L∈Λ there is M∈Λ such that LM=βM. e.g the function f(n)=n2, has two fixed points 0 and 1. The successor function s(n)=n+1 has no fixed point at all.